// admin/system/service/sys_job_log_service.go
package service

import (
	repo "go-admin1/admin/system/dao"
	"go-admin1/admin/system/model"
)

// SysJobLogService 任务日志服务接口
type SysJobLogService interface {
	Create(jobLog *model.SysJobLog) error
	GetByID(id int64) (*model.SysJobLog, error)
	Delete(id int64) error
	List(page, pageSize int) ([]*model.SysJobLog, int64, error)
	CleanAll() error
}

type sysJobLogService struct {
	jobLogDao repo.SysJobLogDao
}

func (s sysJobLogService) Create(jobLog *model.SysJobLog) error {
	return s.jobLogDao.Create(jobLog)
}

func (s sysJobLogService) GetByID(id int64) (*model.SysJobLog, error) {
	jobLog, err := s.jobLogDao.GetByID(id)
	if err != nil {
		return nil, err
	}
	return jobLog, nil
}

func (s sysJobLogService) Delete(id int64) error {
	return s.jobLogDao.Delete(id)
}

func (s sysJobLogService) List(page, pageSize int) ([]*model.SysJobLog, int64, error) {
	jobLogs, total, err := s.jobLogDao.List(page, pageSize)
	if err != nil {
		return nil, 0, err
	}
	return jobLogs, total, nil
}

func (s sysJobLogService) CleanAll() error {
	return s.jobLogDao.CleanAll()
}

// NewSysJobLogService 创建任务日志服务实例
func NewSysJobLogService() SysJobLogService {
	return &sysJobLogService{
		jobLogDao: repo.NewSysJobLogDao(),
	}
}
